home *** CD-ROM | disk | FTP | other *** search
- unit OverlaidImageList;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
-
- type
- // This image list allows you to define overlays for the main images. The first
- // OverlayCount images are overlayed onto the other images. At run time each
- // set of images is overlayed with the overlays.
- TOverlaidImageList = class(TImageList)
- private
- FOverlayCount: TOverlay;
- NonOverlayCount: Integer;
- protected
- procedure Loaded; override;
- function GetOverlayedImageIndex (ThisOverlayIndex: Integer; ThisImageIndex: Integer): Integer;
- public
- property OverlayedImageIndex [OverlayIndex: Integer; ImageIndex: Integer]: Integer read GetOverlayedImageIndex;
- published
- property OverlayCount: TOverlay read FOverlayCount write FOverlayCount;
- end;
-
- const
- NoOverlay = -1;
-
- implementation
-
- function TOverlaidImageList.GetOverlayedImageIndex (ThisOverlayIndex: Integer; ThisImageIndex: Integer): Integer;
- // Returns the index of the image overlayed with the given overlay.
- begin
- Assert ((ThisOverlayIndex = NoOverlay) or (ThisOverlayIndex in [0..3]), 'Overlay must be between 0 and 3.');
- // The first set of images are the overlays, the 2nd set not overlayed, the 3rd set with overlay[0] and so on.
- Result := (NonOverlayCount * (ThisOverlayIndex + 1)) + ThisImageIndex;
- end;
-
- procedure TOverlaidImageList.Loaded;
- var
- WorkList: TImageList;
- ThisImage: Integer;
- WorkBitmap: TBitmap;
- ThisOverlay: Integer;
- begin
- inherited;
-
- NonOverlayCount := Count - OverlayCount;
- if not (csDesigning in ComponentState) and (OverlayCount > 0) then begin
- if OverlayCount > Count then begin
- raise EListError.Create ('Overlay count exceeds image count');
- end;
- WorkList := TImageList.CreateSize (Self.Width, Self.Height);
- WorkBitmap := TBitmap.Create;
- try
- // Copy all our non-overlayed images to a temp image list.
- WorkList.Assign (Self);
- // overlay each image in turn and add it to the working list.
- for ThisOverlay := 0 to OverlayCount - 1 do begin
- // Register the overlay.
- Overlay (ThisOverlay, ThisOverlay);
- for ThisImage := 0 to NonOverlayCount - 1 do begin
- // Clear out the bitmap.
- WorkBitmap.Create;
- WorkBitmap.Height := Self.Height;
- WorkBitmap.Width := Self.Width;
- // Overlay the main image with it's overlay onto the bitmap.
- DrawOverlay (WorkBitmap.Canvas, 0, 0, OverlayCount + ThisImage, ThisOverlay);
- // Add this to the working list.
- WorkList.Add (WorkBitmap, nil);
- end;
- end;
- // Now copy the overwrite me with the working images.
- Assign (WorkList);
- finally
- WorkList.Free;
- WorkBitmap.Free;
- end;
- end;
- end;
-
- end.
-